import { run } from "uebersicht";
import { setWeather } from "./actions.jsx";

export const getDateTime = dispatch => {
	run("date '+%H %M | %a, %d %b, %Y'; whoami").then(output => {
		dispatch({ type: "DATETIME", output });
	});
	setInterval(() => {
		run("date '+%H %M %S %p | %a, %d %b, %Y'; whoami").then(output => {
			dispatch({ type: "DATETIME", output });
		});
	}, 1000);
};

export const getSysInfo = dispatch => {
	run("top -l 1 | head -n 7").then(output => dispatch({ type: "SYSINFO", output }));
	setInterval(() => {
		run("top -l 1 | head -n 7").then(output => dispatch({ type: "SYSINFO", output }));
	}, 1000);
};

export const getWeather = dispatch => {
	setWeather().then(data => {
		dispatch({ type: "WEATHER", data });
	});
	setInterval(() => {
		setWeather().then(data => {
			dispatch({ type: "WEATHER", data });
		});
	}, 600000); // 10 minutes
};
